package qaz.activity;

import java.util.ArrayList;

import qaz.adapter.IconNewsAdapter;
import qaz.adapter.NewsTitleAdapter;
import qaz.news.NewsTitle;
import qaz.news.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class CategoryActivity extends Activity {
	private ListView lvListCategory;
	private ArrayList<NewsTitle> listCategory;
	private NewsTitleAdapter newsAdapter;
	private static TextView tvMarqueTitle;
	private static String  marqueTitle;
	private int index;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		setContentView(R.layout.news_list_title_layout);
		ImageView imgHeader= (ImageView)findViewById(R.id.header_image);
		tvMarqueTitle=(TextView)findViewById(R.id.tv_marque);
		lvListCategory = (ListView) findViewById(R.id.lv_list_title);
		listCategory = new ArrayList<NewsTitle>();
		Bundle extras = getIntent().getExtras(); 
		//int index;
		String content=null;
		if (extras != null) {
		    index = extras.getInt("INDEX");
		    content= extras.getString("CONTENT");
		    tvMarqueTitle.setText(IconNewsAdapter.name[index]);
		    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(36, 18);
		    imgHeader.setLayoutParams(layoutParams);
		    
		    imgHeader.setImageResource(IconNewsAdapter.mThumbIds[index]);
		}
		
		//String title= getIntent().getExtras().getString("NEWS");
		
		for (int i = 0; i < 10; i++) {
			NewsTitle t = new NewsTitle(""+content + String.valueOf(i));
					
			listCategory.add(t);
		}
		
		marqueTitle=tvMarqueTitle.getText().toString();
		newsAdapter= new NewsTitleAdapter(this,R.layout.news_title_row, listCategory);
		
		lvListCategory.setAdapter(newsAdapter);
		lvListCategory.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Log.i("TestNews","clicked at " + arg2);
				Intent i= new Intent(getApplicationContext(), ArticleActivity.class);
				i.putExtra("INDEX",index);
				i.putExtra("HEADNAME", (marqueTitle.concat("-")).concat(listCategory.get(arg2).getTitle()));
				startActivity(i);
			}
		});
	}
}
